package com.example.moblie.poll;

import android.os.Parcel;
import android.os.Parcelable;



public class Poll implements Parcelable{
	private static final String IMG_DIRECTORY = "http://myfyp.no-ip.org/cs4295/image/";
	private int id;
	private int creatorid;
	private String creatorName;
	private String title;
	private int groupid = 0;
	private String dateCreated;
	private double latitude;
	private double longitude;
	private String imgPath;
	
	public Poll(){
		//for test only
	}
	
	public Poll(Parcel in){
		this.id = in.readInt();
		this.creatorid = in.readInt();
		this.creatorName = in.readString();
		this.title = in.readString();
		this.dateCreated = in.readString();
		this.groupid = in.readInt();
		this.latitude = in.readDouble();
		this.longitude = in.readDouble();
		this.imgPath = in.readString();
	}
	
	public Poll(int id, int creatorid,String creatorName, String title, String dateCreated, int groupid, double latitude, double longitude, String imgPath){
		this.id = id;
		this.creatorid = creatorid;
		this.creatorName = creatorName;
		this.title = title;		
		this.dateCreated = dateCreated;
		this.groupid = groupid;	//-1 = null, need if-clause when get polls with a groupid
		this.latitude = latitude;
		this.longitude = longitude;
		this.imgPath = Poll.IMG_DIRECTORY + ((imgPath.equals("null"))?"no_image.jpg":imgPath);
	}
	
	public String getImgPath() {
		return imgPath;
	}

	public void setImgPath(String imgPath) {
		this.imgPath = imgPath;
	}

	public String getCreatorName() {
		return creatorName;
	}

	public void setCreatorName(String creatorName) {
		this.creatorName = creatorName;
	}

	public static final Parcelable.Creator<Poll> CREATOR
    = new Parcelable.Creator<Poll>() 
   {
         public Poll createFromParcel(Parcel in) 
         {
             return new Poll(in);
         }

         public Poll[] newArray (int size) 
         {
             return new Poll[size];
         }
    };
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public int getCreatorid() {
		return creatorid;
	}
	public void setCreatorid(int creatorid) {
		this.creatorid = creatorid;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public int getGroupid() {
		return groupid;
	}
	public void setGroupid(int groupid) {
		this.groupid = groupid;
	}
	public String getDateCreated() {
		return dateCreated;
	}
	public void setDateCreated(String dateCreated) {
		this.dateCreated = dateCreated;
	}
	public double getLatitude() {
		return latitude;
	}
	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}
	public double getLongitude() {
		return longitude;
	}
	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		// TODO Auto-generated method stub
		dest.writeInt(this.id);
		dest.writeInt(this.creatorid);
		dest.writeString(this.creatorName);
		dest.writeString(this.title);
		dest.writeString(this.dateCreated);
		dest.writeInt(this.groupid);
		dest.writeDouble(this.latitude);
		dest.writeDouble(this.longitude);
		dest.writeString(this.imgPath);
	}
}
